package com.sgb.kjwl.view.ui.adapter.self.logistics;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.GoodsManageItemData;
import com.sgb.kjwl.model.entity.transport.AffiliatedFCarEntity;
import com.sgb.kjwl.utils.NumberUtil;

import java.util.Collections;
import java.util.List;

/**
 * @author: 杨畔
 * @date: 2021/7/20 15:32
 * @Description: 货源管理列表适配器
 */
public class LinkedFDetailsAdapter extends BaseQuickAdapter<AffiliatedFCarEntity, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public LinkedFDetailsAdapter(@Nullable List<AffiliatedFCarEntity> data) {
        super(R.layout.item_shared_vehicle, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, AffiliatedFCarEntity item) {
        helper.addOnClickListener(R.id.cl_item_vh);
        if (TextUtils.isEmpty(item.getImgUrl())) {
            helper.setImageResource(R.id.iv_avatar, R.mipmap.ic_car_manager_default);
            helper.setBackgroundRes(R.id.iv_avatar, R.mipmap.ic_car_manager_default);
        } else {
            Glide.with(helper.itemView).load(item.getImgUrl())
                    .apply(new RequestOptions().centerCrop())
                    .into((ImageView) helper.getView(R.id.iv_avatar));
        }
        helper.setText(R.id.tv_shared_cehicle_name, item.getCarNumber());
        helper.setText(R.id.tv_shared_cehicle_info, (TextUtils.isEmpty(item.getCarTypeName()) ? "" : item.getCarTypeName() + "/") + (TextUtils.isEmpty(item.getCarLenName()) ? "" : "长" + item.getCarLenName() + "/") + (TextUtils.isEmpty(item.getCarWeightName()) ? "" : NumberUtil.trim0(item.getCarWeightName()) + "吨"));
    }
}
